//
//  JQFYMyShowCell.m
//  JQFY
//
//  Created by 代辉 on 2017/8/23.
//  Copyright © 2017年 yannis. All rights reserved.
//

#import "JQFYMyShowCell.h"
#import "UIImage+JQFYCornerRandius.h"

@interface JQFYMyShowCell ()

@property (nonatomic,strong) UIImageView *showIcon;
@property (nonatomic,strong) UILabel *name;
@property (nonatomic,strong) UILabel *address;
@property (nonatomic,strong) UILabel *time;
@property (nonatomic,strong) UIButton *checkTicket;

@end

@implementation JQFYMyShowCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = [UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self setupUI];
    }
    return self;
}
- (void)setupUI
{
    UIImageView *bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"my_show_bg"]];
    [self.contentView addSubview:bgImageView];
    [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(40 *SCAL);
        make.top.equalTo(self.contentView).offset(20 *SCAL);
        make.right.equalTo(self.contentView).offset(-20 *SCAL);
        make.bottom.equalTo(self.contentView);
    }];
    
    [self.contentView addSubview:self.showIcon];
    [self.showIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(20 *SCAL);
        make.centerY.equalTo(bgImageView);
    }];
    
    [self.contentView addSubview:self.name];
    [self.name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.showIcon.mas_right).offset(15 *SCAL);
        make.top.equalTo(self.showIcon).offset(5 *SCAL);
        make.width.mas_equalTo(200*SCAL);
    }];
    
    [self.contentView addSubview:self.time];
    [self.time mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.showIcon).offset(-8 *SCAL);
        make.left.equalTo(self.name);
        make.width.mas_equalTo(200*SCAL);
    }];
    
    [self.contentView addSubview:self.address];
    [self.address mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.time);
        make.bottom.equalTo(self.time.mas_top).offset(-3 *SCAL);
        make.width.mas_equalTo(200*SCAL);
    }];
    
    [self.contentView addSubview:self.checkTicket];
    [self.checkTicket mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.showIcon).offset(-4 *SCAL);
        make.right.equalTo(self.contentView).offset(-30 *SCAL);
    }];
    
    [self.checkTicket addTarget:self action:@selector(checkTikect) forControlEvents:UIControlEventTouchUpInside];
}
- (void)setModel:(JQFYMyshowListModel *)model
{
    _model = model;
    self.name.text = model.user_ticket_name;
    self.address.text = model.user_ticket_addr;
    self.time.text = model.user_ticket_time;
    
    self.checkTicket.enabled = [model.pay_status integerValue];
    self.showIcon.image = [model.pay_status integerValue] == 0 ? [UIImage imageNamed:@"未支付（合并）"] : [UIImage imageNamed:[NSString stringWithFormat:@"%zd",arc4random_uniform(11)]];
}
#pragma mark - checkTikect -
- (void)checkTikect
{
    [[NSNotificationCenter defaultCenter] postNotificationName:AleartCheckTikectNoification object:@(1) userInfo:@{OrderID:self.model.out_trade_no}];
}

/**
 show头像
 */
- (UIImageView *)showIcon
{
    if (_showIcon == nil) {
        _showIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"show_icon"]];
    }
    return _showIcon;
}

/**
 演出名字
 */
- (UILabel *)name
{
    if (_name == nil) {
        _name = [UILabel new];
        _name.text = @"2017UNINHIBITED NIGHT";
        _name.textColor = [UIColor colorWithHex:0x9053EB];
        _name.font = [UIFont fontWithName:@"ArialRoundedMTBold" size:15];
    }
    return _name;
}

/**
 地址
 */
- (UILabel *)address
{
    if (_address == nil) {
        _address = [UILabel new];
        _address.textColor = [UIColor darkGrayColor];
        _address.font = [UIFont systemFontOfSize:11];
        _address.text = @"上海UNINHIBITED CLUB";
    }
    return _address;
}

/**
 时间
 */
- (UILabel *)time
{
    if (_time == nil) {
        _time = [UILabel new];
        _time.text = @"2017/12/12";
        _time.font = [UIFont systemFontOfSize:11];
        _time.textColor = [UIColor darkGrayColor];
    }
    return _time;
}

- (UIButton *)checkTicket
{
    if (_checkTicket == nil) {
        _checkTicket = [UIButton buttonWithType:UIButtonTypeCustom];
        [_checkTicket setBackgroundImage:[UIImage imageNamed:@"look_ticket"] forState:UIControlStateNormal];
        [_checkTicket setImage:[UIImage imageNamed:@"查看入场券"] forState:UIControlStateNormal];
    }
    return _checkTicket;
}
@end
